var table = {
    loadData: function (obj, dataType) {
        document.querySelector(obj).GM({
            gridManagerName: 'GM-' + dataType,
            minHeight: '600px',
            ajaxData: com.loadUrl(dataType, 2),
            supportCheckbox: true, //  是否多选
            ajaxType: 'GET',
            supportAjaxPage: dataType == 'formCustoms' ? false : true,  //  开启分页
            supportAdjust: true,   //  是否支持宽度调整功能
            supportDrag: false, //  是否允许拖拽列
            supportAutoOrder: true,    //  是否支持序号
            columnData: table.loadColumn(dataType),
            query: table.loadParas(dataType),
            checkedAfter: function (checkedList) {
                //  选择数据
                if (checkedList.length > 0) {
                    console.log(checkedList)
                    $("#bt-del, #bt-complate").attr("disabled", false);
                    var dataIds = "";
                    $.each(checkedList, function (i, e) {
                        switch (dataType) {
                            case "dics":
                                dataIds = dataIds.length == 0 ? e.dicid : dataIds + ',' + e.dicid;
                                break;
                            case "msgs":
                            case "notices":
                            case "tasklst":
                                dataIds = dataIds.length == 0 ? e.id : dataIds + ',' + e.id;
                                break;
                            case "users":
                                dataIds = dataIds.length == 0 ? e.userid : dataIds + ',' + e.userid;
                                break;
                            case "orderType":
                                dataIds = dataIds.length == 0 ? e.tid : dataIds + ',' + e.tid;
                                break;

                        }
                    });
                    $("#HiddataIds,#oid,#cid").val(dataIds);
                    for(let i in checkedList){  //这里是用来判断当前时间是否逾期了，如果当前系统时间 > 选中框中的计划完成时间，那么就算是逾期。
                        let early = new Date(checkedList[0].taskplanenddate)
                        let format = new Date(checkedList[i].taskplanenddate)
                        if(format < early){
                            early = format
                            console.log(early)
                            if(early > sendT.getCurrentT()){
                                $("#btn-overtimes").attr("disabled", false)
                            }
                            else {$("#btn-overtimes").attr("disabled", true)}
                        }
                        else {
                            $("#btn-overtimes").attr("disabled", false)
                        }
                    }
                } else {
                    $("#HiddataIds").val("");
                    $("#bt-del, #bt-complate").attr("disabled", true);
                    $("#btn-overtimes").attr("disabled", true);
                }
            },
            ajaxSuccess: function (response) {
                // console.log(response)
                var result = JSON.parse(response);
                if (result.data == null && result.msg.indexOf('token 无效') > -1) {
                    parent.location.href = "../Login.jsp";
                }
                //  检查权限
                com.checkAuth(dataType);
                $("[data-tooltip='tooltip']").tooltip();
            }
        });
    },
    //  加载数据列
    loadColumn: function (dataType) {
        var dataColumn = [];
        switch (dataType) {
            case "dics":    //  字典
                dataColumn = [
                    {
                        key: 'classname',
                        text: '分类名称'
                    },
                    {
                        key: 'content',
                        text: '字典内容'
                    },
                    {
                        key: 'remark',
                        text: '备注'
                    },
                    {
                        key: 'orderbyid',
                        text: '排序ID'
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('delete', row.dicid, 'dics');
                        }
                    }
                ];
                break;
            case "notices": //  公告
                dataColumn = [
                    {
                        key: 'contentUpdate',
                        text: '公告内容'
                    },
                    {
                        key: 'dateValidity',
                        text: '有效期',
                        template: table.formatterDate,
                        width: '100px'
                    },
                    {
                        key: 'createdate',
                        text: '创建日期',
                        template: table.formatterDate,
                        width: '100px'
                    },
                    {
                        key: 'readstatus',
                        text: '已读',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return row.readcount + '/' + row.usercount;
                        }
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('delete', row.id, 'notices');
                        }
                    }
                ];
                break;
            case "msgs": //  消息
                dataColumn = [
                    {
                        key: 'datatype',
                        text: '消息类型',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var strCell = "未定义";
                            switch (cell) {
                                case 10:
                                    strCell = "审批";
                                    break;
                            }
                            return strCell;
                        }
                    },
                    {
                        key: 'describe',
                        text: '消息内容',
                        template: function (cell, row, index, key) {
                            var result = "";
                            if (row.jumpstatus == 1) {
                                result = "<span>" + cell + "</span>";
                            } else {
                                result = "<a onclick='opt.updateMsgStatus(" + row.id + ")' >" + cell + "</a>";
                            }
                            return result;
                        }
                    },
                    {
                        key: 'createuser',
                        text: '操作人',
                        width: '100px'
                    },
                    {
                        key: 'createdate',
                        text: '创建日期',
                        template: table.formatterDate,
                        width: '100px'
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return com.loadBtIcon('delete', row.id, 'msgs');
                        }
                    }
                ];
                break;
            case "users": //  用户
                dataColumn = [
                    {
                        key: 'name',
                        text: '姓名'
                    },
                    {
                        key: 'deptname',
                        text: '部门名称'
                    },
                    {
                        key: 'jobnames',
                        text: '职务'
                    },
                    {
                        key: 'tel',
                        text: '联系电话'
                    },
                    {
                        key: 'mobile',
                        text: '手机号码'
                    },
                    {
                        key: 'dataauth',
                        text: '数据权限',
                        width: '150px',
                        template: function (cell, row, index, key) {
                            return "<a data-toggle=\"modal\" data-target=\"#modal-auths\" onclick=\"table.setUserId('" + row.userid + "')\" style='font-size: 15px;  '><i class='fa fa-gear'></i></a>";
                        }
                    },
                    {
                        key: 'deptauth',
                        text: '附加权限',
                        width: '150px',
                        template: function (cell, row, index, key) {
                            return "<a data-toggle=\"modal\" data-target=\"#modal-menus\" onclick=\"table.setUserId('" + row.userid + "')\" style='font-size: 15px; '><i class='fa fa-gear'></i></a>";
                        }
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('query', row) +
                                com.loadBtIcon('delete', row.userid, 'users');
                        }
                    }
                ];
                break;
            case "formCustoms": //  用户自定义表单
                dataColumn = [
                    {
                        key: 'fname',
                        text: '表单名称'
                    },
                    {
                        key: 'ftype',
                        text: '表单类型',
                        template: function (cell, row, index, key) {

                            var mName = "未定义";
                            switch (cell) {
                                case 0:
                                    mName = "文本";
                                    break;
                                case 1:
                                    mName = "下拉选项";
                                    break;
                                case 2:
                                    mName = "日期";
                                    break;
                                case 3:
                                    mName = "大文本";
                                    break;
                            }
                            return mName;
                        }
                    },
                    {
                        key: '大文本',
                        text: '是否必填',
                        template: function (cell, row, index, key) {
                            return cell == 1 ? "是" : "否";
                        }
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {

                            var jsonObj = JSON.stringify(row);
                            var iClass = "fa-edit";
                            var strAttr = "data-toggle='modal' data-target='#modal-defined' onclick='com.clearFormData(),com.loadFromItem(" + jsonObj + ")'";
                            var strColor = ";color:forestgreen";

                            return "<a " + strAttr + " style='font-size: 15px; margin-left: 5px" + strColor + "'><i class='fa " + iClass + "'></i></a>" +
                                com.loadBtIcon('delete', row.fid, 'formCustoms');
                        }
                    }
                ];
                break;
            case "cus": //  客户
                dataColumn = [
                    {
                        key: 'cuscode',
                        text: '客户编码',
                        width: '100px'
                    },
                    {
                        key: 'cusname',
                        text: '客户名称'
                    },
                    {
                        key: 'cusclass',
                        text: '客户分类',
                        width: '100px'
                    },
                    {
                        key: 'address',
                        text: '地址'
                    },
                    {
                        key: 'contacts',
                        text: '联系人',
                        width: '100px'
                    },
                    {
                        key: 'city',
                        text: '国家/城市'
                    },
                    {
                        key: 'status',
                        text: '状态',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = "";
                            var spanContent = "";
                            switch (row.status) {
                                case 0:
                                    spanColor = "info";
                                    spanContent = "未提交";
                                    break;
                                case 1:
                                    spanColor = "warning";
                                    spanContent = "待处理";
                                    break;
                                case -1:
                                    spanColor = "danger";
                                    spanContent = "已驳回";
                                    break;
                                case 2:
                                    spanColor = "primary";
                                    spanContent = "已完成";
                                    break;
                            }
                            return "<span class=\"label label-" + spanColor + "\">" + spanContent + "</span>";
                        }
                    },
                    {
                        key: 'createuser',
                        text: '销售人员',
                        width: '100px'
                    },
                    {
                        key: 'createdate',
                        text: '创建日期',
                        template: table.formatterDate,
                        width: '100px'
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('delete', row.id, 'cus') +
                                com.loadBtIcon('submit', row.id, 'cus') +
                                com.loadBtIcon('export', row.id, 'cus');
                        }
                    }
                ];
                break;
            case "orderType": //  工单类型
                dataColumn = [
                    {
                        key: 'tname',
                        text: '名称'
                    },
                    {
                        key: 'tcode',
                        text: '编码',
                        width: '100px'
                    },
                    {
                        key: 'tclass',
                        text: '类别',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = cell ? "danger" : "info";
                            var title = cell ? "认领" : "指派";
                            return com.loadSpan(title, spanColor);
                        }
                    },
                    {
                        key: 'deptnames',
                        text: '认领部门',
                        width: '120px'
                    },
                    {
                        key: 'contacts',
                        text: '是否支持退单',
                        width: '120px',
                        template: function (cell, row, index, key) {
                            var spanColor = cell ? "success" : "danger";
                            var title = cell ? "是" : "否";
                            return com.loadSpan(title, spanColor);
                        }
                    },
                    {
                        key: 'remarks',
                        text: '备注'
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('delete', row.tid, 'orderType');
                        }
                    }
                ];
                break;
            case "orders": //  工单管理
                dataColumn = [
                    {
                        key: 'tname',
                        text: '工单类型',
                        width: '150px',
                    },
                    {
                        key: 'tclass',
                        text: '类别',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = cell ? "danger" : "info";
                            var title = cell ? "认领" : "指派";
                            return com.loadSpan(title, spanColor);
                        }
                    },
                    {
                        key: 'tcode',
                        text: '编码',
                        width: '100px'
                    },
                    {
                        key: 'wname',
                        text: '任务'
                    },
                    {
                        key: 'createdate',
                        text: '创建时间',
                        width: '120px',
                        template: table.formatterDate,
                    },
                    {
                        key: 'worker',
                        text: '执行人',
                        width: '120px'
                    },
                    {
                        key: 'contacts',
                        text: '状态',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = cell ? "success" : "danger";
                            var title = cell ? "是" : "否";
                            return com.loadSpan(title, spanColor);
                        }
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('delete', row.tid, 'orderType');
                        }
                    }
                ];
                break;
            case "tasklst": //任务派发列表
                dataColumn = [
                    {
                        key: 'taskcontent',
                        text: '任务内容',
                        width: '200px',
                    },
                    {
                        key: 'sendtaskuser',
                        text: '派发人',
                        width: '100px',
                    },
                    {
                        key: 'maketaskuser',
                        text: '执行人',
                        width: '100px',
                    },
                    {
                        key: 'taskfirstdate',
                        text: '计划发起时间',
                        width: '150px',
                        template: table.formatterDate
                    },
                    {
                        key: 'taskplanenddate',
                        text: '计划完成时间',
                        width: '150px',
                        template: table.formatterDate
                    },
                    {
                        key: 'taskisread',
                        text: '已读',
                        width: '70px',
                        template: function (cell, row, index, key) {
                            var spanColor = "";
                            var spanContent = "";
                            switch (row.taskisread ) {
                                case 0:
                                    spanColor = "success";
                                    spanContent = "未读";
                                    break;
                                case null:
                                    spanColor = "success";
                                    spanContent = "未读";
                                    break;
                                case 1:
                                    spanColor = "primary";
                                    spanContent = "已读";
                                    break;
                            }
                            return "<span class=\"label label-" + spanColor + "\">" + spanContent + "</span>";
                        }
                    },
                    {
                        key: 'taskfeedbackdate',
                        text: '计划阶段反馈',
                        width: '150px',
                        template: table.formatterDate
                    },
                    {
                        key: 'taskenddate',
                        text: '实际完成时间',
                        width: '150px',
                        template: table.formatterDate
                    },
                    {
                        key: 'latefeedbackdate',
                        text: '计划逾期反馈',
                        width: '150px',
                        template: table.formatterDate
                    },
                    {
                        key: 'taskstatus',
                        text: '状态',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = "";
                            var spanContent = "";
                            switch (row.taskstatus) {
                                case "-2":
                                    spanColor = "default";
                                    spanContent = "未提交";
                                    break;
                                case "-1":
                                    spanColor = "primary";
                                    spanContent = "执行中";
                                break;
                                case "0":
                                    spanColor = "danger";
                                    spanContent = "已逾期";
                                break;
                                case "1":
                                    spanColor = "warning";
                                    spanContent = "待审核";
                                break;
                                case "2":
                                    spanColor = "danger";
                                    spanContent = "已撤销";
                                    break;
                                case "3":
                                    spanColor = "success";
                                    spanContent = "已完成";
                                break;
                            }
                            return "<span class=\"label label-" + spanColor + "\">" + spanContent + "</span>";
                        }
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (call, row, index, key){
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('delete', row.id, 'tasklst') +
                                com.loadBtIcon('submit', row.id, 'tasklst') +
                                com.loadBtIcon('takeback', row.id, "tasklst");
                        }
                    }
                ]
                break;
            case "inquiry":
                dataColumn = [
                    {
                        key: 'inquirydate',
                        text: '询价日期',
                        width: "150px",
                        template: table.formatterDate
                    },
                    {
                        key: 'country',
                        text: '国家',
                        width: '100px',
                    },
                    {
                        key: 'company',
                        text: '公司名称',
                        width: '100px',
                    },
                    {
                        key: 'logistics',
                        text: '物流',
                        width: '100px',
                    },
                    // {
                    //     key: 'forwarder',
                    //     text: '询价货代',
                    //     width: '100px',
                    // },
                    {
                        key: 'goodsweight',
                        text: '重量',
                        width: '100px'
                    },
                    {
                        key: 'inquiryprice',
                        text: '询价金额',
                        width: '100px'
                    },
                    {
                        key: 't6price',
                        text: 'T6金额',
                        width: '100px'
                    },
                    // {
                    //     key: 'logisticsprice',
                    //     text: '货代报价',
                    //     width: '100px',
                    // },
                    {
                        key: 'liquidation',
                        text: '双清',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = "";
                            var spanContent = "";
                            switch (row.liquidation) {
                                case 0:
                                    spanColor = "primary";
                                    spanContent = "是";
                                    break;
                                case 1:
                                    spanColor = "danger";
                                    spanContent = "否";
                                    break;
                            }
                            return "<span class=\"label label-" + spanColor + "\">" + spanContent + "</span>";
                        }
                    },
                    {
                        key: 'liquidationprice',
                        text: '双清金额',
                        width: '100px'
                    },
                    {
                        key: 'goodsdeclare',
                        text: '报关',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = "";
                            var spanContent = "";
                            switch (row.goodsdeclare) {
                                case 0:
                                    spanColor = "primary";
                                    spanContent = "是";
                                    break;
                                case 1:
                                    spanColor = "danger";
                                    spanContent = "否";
                                    break;
                            }
                            return "<span class=\"label label-" + spanColor + "\">" + spanContent + "</span>";
                        }
                    },
                    {
                        key: 'goodsdeclareprice',
                        text: '报关金额',
                        width: '100px'
                    },
                    {
                        key: 'ageing',
                        text: '时效(天)',
                        width: '100px'
                    },
                    {
                        key: 'risk',
                        text: '限电/风险',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = "";
                            var spanContent = "";
                            switch (row.risk) {
                                case 0:
                                    spanColor = "primary";
                                    spanContent = "是";
                                    break;
                                case 1:
                                    spanColor = "danger";
                                    spanContent = "否";
                                    break;
                            }
                            return "<span class=\"label label-" + spanColor + "\">" + spanContent + "</span>";
                        }
                    },
                    {
                        key: 'waybill',
                        text: '单号',
                        width: '180px',
                    },
                    {
                        key: 'sales',
                        text: '销售人员',
                        width: '100px',
                    },
                    {
                        key: 'fowarderstaff',
                        text: '货代人员',
                        width: '100px'
                    },
                    // {
                    //     key: 'actualprice',
                    //     text: '实发金额',
                    //     width: '100px'
                    // },
                    {
                        key: 'actualweight',
                        text: '实发重量',
                        width: '100px'
                    },
                    {
                        key: 'transferwaybill',
                        text: '转运单号',
                        width: '150px',
                    },
                    {
                        key: 'rate',
                        text: '汇率',
                        width: '100px'
                    },
                    {
                        key: 'formstatus',
                        text: '状态',
                        width: '100px',
                        template: function (cell, row, index, key) {
                            var spanColor = "";
                            var spanContent = "";
                            switch (row.formstatus) {
                                case -1:
                                    spanColor = "default";
                                    spanContent = "未提交";
                                    break;
                                case 0:
                                    spanColor = "primary";
                                    spanContent = "已提交";
                                    break;
                                case 1:
                                    spanColor = "warning";
                                    spanContent = "待确认";
                                    break;
                                case 2:
                                    spanColor = "success";
                                    spanContent = "已完成";
                                    break;
                            }
                            return "<span class=\"label label-" + spanColor + "\">" + spanContent + "</span>";
                        }
                    },
                    {
                        key: 'operate',
                        text: '操作',
                        width: '100px',
                        template: function (call, row, index, key){
                            return com.loadBtIcon('edit', row) +
                                com.loadBtIcon('delete', row.id, 'inquiry') +
                                com.loadBtIcon('submit', row.id, 'inquiry') +
                                com.loadBtIcon('takeback', row.id, 'inquiry');
                        }
                    }
                ]
        }
        return dataColumn;
    },
    //  设置用户ID
    setUserId: function (userid) {
        $("#userid").val(userid);
    },
    //  加载参数
    loadParas: function (dataType) {
        var dataParas = {searchName: $("#querySeachName").val()};
        switch (dataType) {
            case "msgs":
                dataParas["startDate"] = $("#searchStart").val();
                dataParas["endDate"] = $("#searchEnd").val();
                dataParas["dataType"] = $("#queryDataType").val();
                dataParas["userId"] = $("#queryUserId").val();
                break;
            case "users":
                dataParas["deptCode"] = $("#Hiddeptcode").val();
                dataParas["jobCode"] = $("#queryJobCode").val();
                break;
            case "tasklst":
                dataParas["queryBeginSeachDate"] = $("#queryBeginSeachDate").val();
                dataParas["queryEndSearchDate"] = $("#queryEndSearchDate").val();
            default:
                break;
        }
        return dataParas;
    },
    //  加载日期列
    formatterDate: function (value) {
        return com.formateDateTime(value, 0);
    },
    //  查询数据
    queryData: function (dataType) {
        var _query = table.loadParas(dataType);
        document.querySelector('#table-data').GM('setQuery', _query);
    }
}